home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / MOUSPP30.ARJ / MOUSE.H < prev    next >
C/C++ Source or Header  |  1992-02-21  |  6KB  |  174 lines

  1. /* -------------------------------------------------------------------- */
  2. /* Mouse++ Version 3.0             mouse.h             Revised 02/21/92 */
  3. /*                                                                      */
  4. /* General mouse class for Turbo C++/Borland C++.                       */
  5. /* Copyright 1991, 1992 by Carl W. Moreland                             */
  6. /* This source code may be freely distributed as long as the copyright  */
  7. /* notice remains intact.                                               */
  8. /* -------------------------------------------------------------------- */
  9.  
  10. #ifndef MOUSEdotH
  11. #define MOUSEdotH
  12.  
  13. #define MOUSE_BUFFER_SIZE 8
  14.  
  15. #define LEFTBUTTON    0       // mouse button assignments
  16. #define RIGHTBUTTON    1
  17. #define CENTERBUTTON    2
  18.  
  19. #define CURSORSOFT    0       // used in struct TextCursor
  20. #define CURSORHARD    1
  21.  
  22. #define MOUSE_MOVED    0x01    // event masks for event handler
  23. #define LB_PRESSED      0x02
  24. #define LB_RELEASED     0x04
  25. #define RB_PRESSED      0x08
  26. #define RB_RELEASED     0x10
  27. #define CB_PRESSED      0x20
  28. #define CB_RELEASED     0x40
  29.  
  30. #define SHIFT_PRESSED   0x08    // key shift masks
  31. #define RSHIFT_PRESSED  0x10
  32. #define LSHIFT_PRESSED  0x20
  33. #define CTRL_PRESSED    0x40
  34. #define ALT_PRESSED     0x80
  35.  
  36. #define EventExit() __emit__(0x5D,0x5F,0x5E,0x1F,0x07,\
  37.                              0x5A,0x59,0x5B,0x58,0xCB);
  38.  
  39. /* -------------------------------------------------------------------
  40. The above emitted code is equivalent to the following assembler code:
  41.  
  42.        pop   bp
  43.        pop   di
  44.        pop   si
  45.        pop   ds
  46.        pop   es   ;interrupt exit processing
  47.        pop   dx
  48.        pop   cx
  49.        pop   bx
  50.        pop   ax
  51.        retf       ;far return
  52.    ------------------------------------------------------------------- */
  53.  
  54. void interrupt MouseHandler(void);
  55.  
  56. struct GraphicsCursor        // structure for graphics cursor (0x09)
  57. {
  58.   unsigned char hotx, hoty;     // hot spot; (0,0) = upper left corner
  59.   unsigned *image;              // 16 x 16 pixel screen and cursor masks
  60. };                // see cursor.h for predefined cursors
  61.  
  62. struct TextCursor               // structure for text cursor (0x0A)
  63. {
  64.   int type;            // hard or soft cursor
  65.   unsigned arg1, arg2;        // screen and cursor masks
  66. };
  67.  
  68. struct OldEventHandler        // structure to save old handler (0x14)
  69. {
  70.   unsigned mask;        // event mask
  71.   unsigned segment, offset;    // address of event handler
  72. };
  73.  
  74. struct MouseInfo        // structure to return data (0x24)
  75. {
  76.   unsigned char type;        // bus=1, serial=2, InPort=3, PS/2=4, HP=5
  77.   unsigned char majorvers;    // software major version
  78.   unsigned char minorvers;    // software minor version
  79.   unsigned char irq;        // IRQ used (2-7), 0 for PS/2
  80. };
  81.  
  82. struct MouseEvent        // event buffer structure
  83. {
  84.   unsigned char event;        // trigger event
  85.   unsigned char button;        // button status
  86.   unsigned int  x, y;        // cursor coordinates
  87.   unsigned int  xcount, ycount;    // mickeys moved since last event
  88.   long time;            // time event occurred
  89. };
  90.  
  91. struct MouseClick        // MultiClick buffer structure
  92. {
  93.   unsigned char count;        // number of clicks
  94.   long time;            // time of last click
  95. };
  96.  
  97. class Mouse
  98. {
  99.   static unsigned char exists;    // 1 if mouse found, 0 if not
  100.   static unsigned char enabled;    // 1 if mouse enabled, 0 if not
  101.   static unsigned char visible;    // keeps track of Hide() & Show()
  102.   static unsigned char buttons; // number of buttons
  103.   static unsigned char button;    // button status
  104.   static int x, y;        // x & y position of cursor
  105.   static int xcount, ycount;    // mickeys moved since last event
  106.   static unsigned char hotx, hoty;    // cursor hot spot coords
  107.   static int oldeventmask;    // oldeventxxx holds info on the event
  108.   static int oldeventseg;    //   handler that was active when Mouse
  109.   static int oldeventoff;    //   was initiated.  Used in restore.
  110.  
  111.   MouseEvent Buffer[MOUSE_BUFFER_SIZE];    // event buffer
  112.   static unsigned char HeadPtr;        // buffer pointer
  113.   static unsigned char TailPtr;        // buffer pointer
  114.   unsigned char eventMask;
  115.   void interrupt (*eventHandler)(void);
  116.   static unsigned char event;        // current event
  117.   static unsigned char handlerInstalled;// event handler flag
  118.  
  119.   MouseClick Click[3];            // MultiClick buffer
  120.   static unsigned clickThreshold;    // MultiClick threshold
  121.  
  122. public:
  123.   Mouse(void);
  124.  ~Mouse(void);
  125.   MouseInfo Info;
  126.  
  127.   unsigned char Exists()  { return exists;  }
  128.   unsigned char Visible() { return visible; }
  129.   unsigned char Buttons() { return buttons; }
  130.   unsigned char Button()  { return button;  }
  131.  
  132.   int  xPos()          { return x;      }
  133.   int  yPos()           { return y;      }
  134.   int  xCount()        { return xcount; }
  135.   int  yCount()        { return ycount; }
  136.   unsigned char LB_Dn()   { return (0x01 & button); }
  137.   unsigned char RB_Dn()   { return (0x02 & button); }
  138.   unsigned char CB_Dn()   { return (0x04 & button); }
  139.  
  140.   void Enable(void);
  141.   void Disable(void);
  142.   void Show(void);
  143.   void Hide(void);
  144.   void Move(int x, int y);
  145.   void Position(void);
  146.   void Motion(void);
  147.   int  Pressed(int mbutton);
  148.   int  Released(int mbutton);
  149.   int  InBox(int left, int top, int right, int bottom);
  150.   void Exclude(int left, int top, int right, int bottom);
  151.   int  MultiClick(int mbutton);
  152.   int  DoubleClick(int mbutton);
  153.   void ClearClick(int mbutton);
  154.  
  155.   void xLimit(int min, int max);
  156.   void yLimit(int min, int max);
  157.   void SetGraphicsCursor(GraphicsCursor& cursor);
  158.   void SetTextCursor(TextCursor& cursor);
  159.   void MickToPix(int horiz, int vert);
  160.   void SetSpeedThreshold(unsigned speed);
  161.   void SetClickThreshold(unsigned time);
  162.  
  163.   void InstallHandler(unsigned mask,
  164.                       void interrupt (*handler)(void) = MouseHandler);
  165.   void ClearHandler(void);
  166.   void Save(int event, int button, int x, int y, int xcount, int ycount);
  167.   void GetEvent(void);
  168.   void ClearEvent(void);
  169.   void ClearBuffer(void);
  170. };
  171.  
  172. extern Mouse mouse;
  173.  
  174. #endif